home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / server.arc / TEST.C < prev    next >
Text File  |  1989-12-06  |  4KB  |  131 lines

  1. /*------------------------------------------------*   
  2.  *          Drop-in TLA server                    *   
  3.  *                                                *   
  4.  *          Written by: Stephen T. Bunch          *   
  5.  *                Engineering services            *   
  6.  *                                                *   
  7.  *          Date:       July 11, 1989             *   
  8.  *                                                *   
  9.  *------------------------------------------------*/   
  10. #include          <stdio.h>   
  11. #define           INCL_BASE   
  12. #include          <os2.h>   
  13. #include          <nwcalls.h>   
  14. #include          <malloc.h>   
  15. #include          "server.h"   
  16. #include          <fcntl.h>   
  17.    
  18. /*   
  19.  *          ! ! ! ! !    N O T E     ! ! ! ! !   
  20.  *   
  21.  *          The index must be already read into memory with a call to ReadIndex()   
  22.  *          from the main program before you can use ServeItUp().   
  23.  */   
  24.    
  25.    
  26. main(argc,argv)   
  27. int argc;   
  28. char *argv[];   
  29. {   
  30.       char filename[20];   
  31.       int modify = FALSE;   
  32.    
  33.       if (argc == 1)   
  34.             PrintUsage();   
  35.       TLAReadIndex();   
  36.       switch (argv[1][1]) {   
  37.             case 'n':   
  38.                   if (argc != 3)   
  39.                          PrintUsage();   
  40.                   strcpy(filename, argv[2]);   
  41.                   modify = TRUE;   
  42.                   NewInput(filename);   
  43.                   break;   
  44.             case 'q':   
  45.                   QueryData(FALSE);   
  46.                   break;   
  47.             default: PrintUsage();   
  48.             }   
  49.       TLACloseIndex();   
  50. }   
  51.    
  52. PrintUsage()   
  53. {   
  54.       printf("\nUsage:  -n filename : input data from 'filename' into TLA database");   
  55.       printf("\n           file format: tla[10]CR expanded[80]CR explaination[160]CR");   
  56.       printf("\n                        the last tla must be 'quit'");   
  57.       printf("\n        -q          : query data base for TLA only");   
  58.       exit(0);   
  59. }   
  60.    
  61. NewInput(filename)   
  62. char *filename;   
  63. {   
  64.       struct COMMBUFFER commbuffer;   
  65.     FILE *finput;   
  66.    
  67.       if ((finput = fopen(filename,"r")) == NULL) {   
  68.             printf("\nError opening input file.");   
  69.             exit(0);   
  70.     }   
  71.    
  72.       while (TRUE) {   
  73.             memset(&commbuffer, 0, sizeof(struct COMMBUFFER));   
  74.             ReadString(commbuffer.record.tla, TLA_SIZE, finput);   
  75.             if (strcmp(commbuffer.record.tla, "quit") == 0)   
  76.                   break;   
  77.             ReadString(commbuffer.record.expanded, 80, finput);   
  78.             ReadString(commbuffer.record.explain, 80, finput);   
  79.             ReadString(&commbuffer.record.explain[80], 80, finput);   
  80.             commbuffer.type |= ADD_TO_LIST;   
  81.             TLAServeItUp(&commbuffer);   
  82.       }   
  83.       commbuffer.type |= SORT;   
  84.       TLAServeItUp(&commbuffer);   
  85. }   
  86.    
  87. ReadString(buffer, size, file)   
  88. char buffer[];   
  89. int size;   
  90. FILE *file;   
  91. {   
  92.       int i;   
  93.       char ch;   
  94.    
  95.       for (i=0; i<size-1; i++) {   
  96.             if ((ch = fgetc(file)) == '\n')   
  97.                   break;   
  98.             else   
  99.                   buffer[i] = ch;   
  100.       }   
  101.       buffer[i] = '\0';   
  102. }   
  103.    
  104. QueryData(getItAll)   
  105. int getItAll;   
  106. {   
  107.       struct COMMBUFFER commbuffer;   
  108.       int ccode;   
  109.    
  110.       while (TRUE) {   
  111.             memset(&commbuffer, 0, sizeof(struct COMMBUFFER));   
  112.             printf("\nEnter TLA to find (q to quit): ");   
  113.             gets(commbuffer.record.tla);   
  114.             if (commbuffer.record.tla[0] == 'q')   
  115.                   break;   
  116.             commbuffer.type |= QUERY;   
  117.             if ((ccode = TLAServeItUp(&commbuffer)) != 0) {   
  118.                   printf("\nError in finding tla %s: %d",commbuffer.record.tla,ccode);   
  119.                   return;   
  120.             }   
  121.             PrintCommBuffer(&commbuffer);   
  122.       }   
  123. }   
  124.    
  125. PrintCommBuffer(commbuffer)   
  126. struct COMMBUFFER *commbuffer;   
  127. {   
  128.       printf("\n%s :   %-60s", commbuffer->record.tla, commbuffer->record.expanded);   
  129.       printf("\n%-70s ", commbuffer->record.explain);   
  130. }   
  131.